<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8"/>
    <meta name="keywords" content=""/>
    <meta name="description" content=""/>
    <title>修改密码</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css"/>
    <link rel="stylesheet" href="/admin/css/common.css">
    <script type="text/javascript" src="/static/layui/layui.js" charset="utf-8"></script>
</head>
<body>
<div class="breadcrumb">
    <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a><cite>修改密码</cite></a>
    </span>
    <a class="layui-btn-xs layui-btn-small" style="float:right;margin-top: 10px;"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon layui-icon-refresh"></i> </a>
</div>
<div style="padding:15px;">
    <form class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <label class="layui-form-label">管理员帐号</label>
            <div class="layui-input-block">
                <input type="text" name="username"  autocomplete="off"  class="layui-input" value="{$user.username}" readonly>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">管理员密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required"  autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class='red'>新密码</span></label>
            <div class="layui-input-block">
                <input type="password" name="new_psd" lay-verify="required"  autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"><span class='red'>确认密码</span></label>
            <div class="layui-input-block">
                <input type="password" name="confirm_psd" lay-verify="required"  autocomplete="off"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <input class="layui-btn" value="立即提交" readonly>
            </div>
        </div>
    </form>
</div>

<script>
    layui.use(['element', 'jquery','form','layer'], function(){
        var $ = layui.jquery
                ,layer = layui.layer
                ,element = layui.element
                ,form = layui.form;

        // 提交数据
        $(document).on("click", ".layui-btn", function() {
            var password = $.trim($("input[name = 'password']").val());
            var new_psd = $.trim($("input[name = 'new_psd']").val());
            var confirm_psd =$.trim($("input[name = 'confirm_psd']").val());
			
			
			if(password.length <= 0 || new_psd.length <= 0 || confirm_psd.length <= 0){
                layer.msg('必填项缺失', {time: 2000});
                return false;
            }


            if (new_psd !== confirm_psd){
                layer.msg('两次输入密码不一致', {time: 2000});
                return false;
            }
            if (password == new_psd){
                layer.msg('新密码不能和原密码一致', {time: 2000});
                return false;
            }
            $.ajax({
                type: 'post',
                url: '{:url("Account/reset_password")}',
                data: {
                    password: password,
                    new_psd:new_psd,
                },
                success: function (result) {
                    if (result.code === 0) {
                        layer.msg(result.msg, {time: 2000});
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.href= "/admin/Account/login";
                        }, 2000)
                    }
                }
            })
        });

    });

</script>
</body>
</html>